package com.ssdp.controller;


import com.ssdp.dto.Result;
import com.ssdp.entity.Voucher;
import com.ssdp.service.IVoucherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author syo 2319615164@qq.com
 * @description 优惠券接口
 * @date 2024/3/14
 * @Copyright syo
 */
@RestController
@RequestMapping("/voucher")
@Api(tags = "优惠券相关接口")
@RequiredArgsConstructor
public class VoucherController {

    private final IVoucherService voucherService;

    @ApiOperation("新增普通优惠券")
    @PostMapping
    public Result addVoucher(@RequestBody Voucher voucher) {
        voucherService.save(voucher);
        return Result.ok(voucher.getId());
    }

    @ApiOperation("新增秒杀优惠券")
    @PostMapping("seckill")
    public Result addSeckillVoucher(@RequestBody Voucher voucher) {
        voucherService.addSeckillVoucher(voucher);
        return Result.ok(voucher.getId());
    }

    @ApiOperation("查询店铺的优惠券列表（包含秒杀券）")
    @GetMapping("/list/{shopId}")
    public Result queryVoucherOfShop(@PathVariable("shopId") Long shopId) {
       return voucherService.queryVoucherOfShop(shopId);
    }
}
